﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MT.eVotePRS.Common.Helper
{
    public class Helper
    {
        public static string ToHex(byte[] buf)
        {
            string s = "";
            for (int i = 0; i < buf.Length; i++)
            {
                s = s + buf[i].ToString("X2");
            }
            return s;
        }

        public static bool IsNumeric(string str)
        {
            char[] chrs = str.ToCharArray();

            return IsNumeric(chrs);
        }

        public static bool IsNumeric(char[] chrs)
        {
            bool returnValue = true;

            for (int i = 0; i < chrs.Length; i++)
            {
                if (chrs[i] < '0' || chrs[i] > '9')
                {
                    returnValue = false;
                    break;
                }
            }

            return returnValue;
        }   

        public static string MaoPao(string arg)
        {
            char ch;
            char[] chars = arg.ToCharArray();
            for (int i = chars.Length - 1; i > 0; --i)
            {
                for (int j = 0; j < i; ++j)
                {
                    if (chars[j] > chars[j + 1])
                    {
                        ch = chars[j];
                        chars[j] = chars[j + 1];
                        chars[j + 1] = ch;
                    }
                }
            }

            return new string(chars);
        }
    }
}
